package cn.wolfcode.luowowo.website.web.controller;

import cn.wolfcode.luowowo.article.domain.Destination;
import cn.wolfcode.luowowo.article.domain.Flight;
import cn.wolfcode.luowowo.article.query.FlightQuery;
import cn.wolfcode.luowowo.article.service.IDestinationService;
import cn.wolfcode.luowowo.article.service.IFlightService;
import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.PageInfo;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/fly")
public class FlightController {
    @Reference
    private IDestinationService destinationService;
    @Reference
    private IFlightService flightService;


    @RequestMapping("")
    public Object index(Model model){
        /**
         * 查询国内热门
         */
        List<Destination> hotFlights =  destinationService.getInChinaAndHot();
        model.addAttribute("hotFlights",hotFlights);

        /**
         * 查询ABCDE
         */
        List<Destination> initialA =  destinationService.getStartAEndE();
        model.addAttribute("initialA",initialA);

        /**
         * 查询FGHJ
         */
        List<Destination> initialF =  destinationService.getStartFEndJ();
        model.addAttribute("initialF",initialF);

        /**
         * 查询KLMNP
         */
        List<Destination> initialK =  destinationService.getStartkEndP();
        model.addAttribute("initialK",initialK);
        /**
         * 查询QRSTW
         */
        List<Destination> initialQ =  destinationService.getStartQEndW();
        model.addAttribute("initialQ",initialQ);
        /**
         * 查询XYZ
         */
        List<Destination> initialX =  destinationService.getStartXEndWZ();
        model.addAttribute("initialX",initialX);


        return "/flight/index";
    }

    @RequestMapping("/serachFly")
    public Object fly(Model model,@ModelAttribute("qo")FlightQuery qo){
        qo.setPageSize(5);
        PageInfo pageInfo = flightService.query(qo);
        model.addAttribute("pageInfo",pageInfo);
        return "/flight/serachFlightTpl";
    }

}
